<?php

namespace App\Http\Resources;

use App\Trip\Enums\TripTypes;
use App\Trip\Orders\TripOrderStateDesc;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

class TripBookOrderResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     *
     * @return array|Arrayable|JsonSerializable
     */
    public function toArray($request)
    {
        $ret = parent::toArray($request);
        return [
            'order_sn'         => $ret['order_sn'],
            'transfer_flag'    => $ret['transfer_flag'],
            'order_state'      => $ret['order_state'],
            'task_id'          => $ret['task_id'] ?? '',
            'snap_up'          => $ret['snap_up'] ?? 0,
            'order_state_desc' => TripOrderStateDesc::transDescByOrderState(TripTypes::TRAIN, $ret['order_state']),
        ];
    }
}
